package com.tank.control;

import com.tank.entrity.GameObject;
import java.util.LinkedList;
import java.util.List;

/**
 * 碰撞器链条
 */
public class ColliderChain implements Collider {
    private final List<Collider> colliders;

    public ColliderChain() {
        this.colliders = new LinkedList<>();
        addCollider(new BulletTankCollider())
                .addCollider(new BulletWallCollider())
                .addCollider(new TankTankCollider())
                .addCollider(new TankWallCollider());
    }

    public ColliderChain addCollider(Collider collider) {
        this.colliders.add(collider);
        return this;
    }

    public boolean collide(GameObject o1, GameObject o2) {
        for (Collider collider : colliders) {
            if (collider.collide(o1, o2)) {
                return true;
            }
        }
        return false;
    }
}
